<template>
   
  <div>
    <div class="but">
      <el-button type="primary" @click="oppen.off = true">添加</el-button>
      <el-button type="warning">批量删除</el-button>
    </div>
    <grid :list="list" :oppen="oppen" @redact="edit" @remove="del"> </grid>
    <grid-add :list="list" :oppen="oppen" ref="editform" :meuns="meuns"></grid-add>
    <!-- //分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pages.page"
      :page-sizes="[2, 4, 6, 8]"
      :page-size="pages.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import grid from "./seed/grid.vue";
import gridAdd from "./seed/gridAdd.vue";
export default {
  data() {
    return {
      pages: {
        page: 1,
        size: 2,
      },
      total: null,
      list: [],
      oppen: {
        off: false,
      },
      meuns:[]
    };
  },
  methods: {
    //分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pages.size = val;
      this.fn();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pages.page = val;
      this.fn();
    },
    //编辑
    edit(row) {
      this.$refs.editform.form = JSON.parse(JSON.stringify(row));
      this.oppen.off = true;
    },
    //删除
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.mangerdel({ id }).then((res) => {
            console.log(res);
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.$router.go(0);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //
    fn() {
      this.$api.manageruser(this.pages).then((res) => {
        console.log(res);
        this.list = res.data.list;
      });
    },
  },
  created() {
    //
    this.fn();
    //分页数据
    this.$api.mangerfy().then((res) => {
      console.log(res);
      this.total = res.data.list[0].total;
    });

    this.$api.reqRole().then(res=>{
      console.log(res);
      this.meuns=res.data.list
    })
  },
  mounted() {},
  components: {
    grid,
    gridAdd,
  },
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
.but {
  margin: 10px 0;
}
</style>
